<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'demo.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    This is my RequestDemo page. <br>
    <h1>赋值方法</h1>
    <p>1.request直接在页面上赋值:request.setAttribute(key,value);</p>
    <p>2.request通过将表单数据封装进request中&lt;input type="text" name="key" value="value"/&gt;</p>
    <h1>取值方法</h1>
    <p>1.赋值方法1取值使用request.getAttribute(arg0);</p>
    <p>2.赋值方法2取值使用request.getParameter(name);使用request.getAttribute(arg0);获取不到值</p>
    <h4>Get提交表单</h4>
    <pre class="brush:html;toolbar:false">
	&lt;form action=&quot;DemoServlet&quot; method=&quot;GET&quot;&gt;
	    &lt;input type=&quot;text&quot; name=&quot;test&quot; value=&quot;我是GET请求&quot;/&gt;
	    &lt;input type=&quot;submit&quot;/&gt;
	&lt;/form&gt;
	</pre>
	<form action="DemoServlet" method="GET">
	    <input type="text" name="test" value="我是GET请求"/>
	    <input type="submit"/>
	</form>
	<p>点击表单提交后经过DemoServlet的doGet方法,在此方法中会设置</p>
	<p>request.setAttribute("name", "由servlet到jsp");</p>
	<p>request.getRequestDispatcher("request.jsp").forward(request, response);<p>
	<p>这样返回到request.jsp页面,直接访问此页面是没有值得,但是通过提交表单经过servlet的处理便对request赋值了.</p>
    <p>request.getAttribute("name"):<span style="color:red;"><%= request.getAttribute("name")%><span></p>
    <h4>Post提交表单</h4>
    <pre class="brush:html;toolbar:false">
	&lt;form action=&quot;DemoServlet&quot; method=&quot;POST&quot;&gt;
	    &lt;input type=&quot;text&quot; name=&quot;test&quot; value=&quot;我是POST请求&quot;/&gt;
	    &lt;input type=&quot;submit&quot;/&gt;
	&lt;/form&gt;
	</pre>
	<form action="DemoServlet" method="POST">
	    <input type="text" name="test" value="我是POST请求"/>
	    <input type="submit"/>
	</form>
	<p>在DemoServlet的doPost方法中保存了一个数据到session,点击post提交钱可以先访问<a href="session.jsp">session.jsp</a>页面,你在这个页面中看到是<span style="color:red">如果是第一次访问此页面session.name为:null<span></p>
  </body>
</html>
